package cn.sh.library.gmwx.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.sh.library.gmwx.bean.OrganizationSearchBean;
import cn.sh.library.gmwx.dto.Pager;
import cn.sh.library.gmwx.dto.QueryResult;
import cn.sh.library.gmwx.service.OrganizationService;
import cn.sh.library.gmwx.sparql.OrganizationSparql;

@Service
public class OrganizationServiceImpl implements OrganizationService {
    @Resource
    private OrganizationSparql organizationSparql;

    @Override
    public List<Map<String, String>> list(OrganizationSearchBean search, Pager pager) {
        String order = "ORDER BY " + pager.getDir() + "(?" + pager.getSort() + ")";

        QueryResult<Map<String, String>> queryResult = this.organizationSparql.searchOrgs(search, order, pager.getStartIndex(), pager.getPageSize());

        pager.calcPageCount(queryResult.getTotalrecord());
//        pager.calcPageCount(Math.min(queryResult.getTotalrecord(), 10000));
        pager.setRowCount(queryResult.getTotalrecord());
        return queryResult.getResultList();
    }
}
